<?php
include_once "com/code/Controller.php";
include_once "com/code/View.php";

class UploadController extends Controller {
	
	private $loginControllerId;
	
	public function __construct($params) {
		parent::__construct($params);
		
		$this->loginControllerId = $params['loginControllerId'];
		$validId = Controller::isControllerSet("LoginController", $this->loginControllerId);
		if (!$validId) {
			throw new Exception('UploadController.__construct(): loginControllerId is not valid.');
		}
	}
	
	public function __destruct() {
		parent::__destruct();
	}
	
	public function getLoginController() {
		return Controller::getController("LoginController", $this->loginControllerId);
	}
	
	public function getUploadView($params) {
		$view = new View("com/code/video/upload/UploadView.php");
		$view->assignController($this);
		$vars = array();
		$view->display($vars);
	}
	
	public function upload($params) {
		$loginController = $this->getLoginController();
		$logged = $loginController->logged();
		
		$view = new View("com/code/video/upload/UploadResultView.php");
		$vars = array();
		
		if ($logged) {
			$vars['message'] = "Se ha subido correctamente el fichero: ".$_FILES['uploaded-file']['name'];
		} else {
			$vars['message'] = "Debes estar logueado para subir un fichero.";
		}
		
		$view->display($vars);
	}
}
?>